import { useUser } from "@/stores/user";
import { ref } from "vue";

const user = useUser();
const isLoding = ref(false);
const pageIdx = ref(1);
const size = 10;

let ResObj = ref<Invite>({
    records: [],
    total: 0,
    size: 0,
    current: 0,
    orders: [],
    optimizeCountSql: true,
    searchCount: true,
    pages: 0
});

async function getInvite() {
    isLoding.value = true;
    const invite: Invite = await user.getInvitePage(size, pageIdx.value);
    if (invite !== null) {
        ResObj.value = invite;
        setTimeout(() => isLoding.value = false, 500);
    } else {
        setTimeout(() => isLoding.value = false, 1000);
    }
}

export { getInvite, isLoding, pageIdx, ResObj };
export type { Invite };

interface Invite {
    records: InviteType[];
    total: number;
    size: number;
    current: number;
    orders: any[];
    optimizeCountSql: boolean;
    searchCount: boolean;
    pages: number;
}

interface InviteType {
    id: number;
    userType: number;
    userName: string;
    email: string;
    recommendId: number;
    regTime: number;
    recommendCode: string;
    energy: number;
    lock: boolean;
}